import {mongo} from "#nuxt-mongodb"
import {ObjectId} from "mongodb"

interface updateUserMes{
    id:string,
    name:string

}

export default defineEventHandler(async (event:any)=>{
    try{
        const {id,name}:updateUserMes = await readBody(event)
        const objectId = new ObjectId(id)
        const db = mongo.db()
        const result = db.collection('user').updateOne({_id:objectId},{$set:{name:name}})
        return {
            stauts:200,
            message:result
        }
    }catch(err:any){
        return {
            stauts: 500,
            message: "update error"
        }
    }

})